<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>e网批发管理后台</title>
	<?php include("common/conn.php"); if($_SESSION['userid']==""){echo "<script>window.location.href='login.php';</script>";} 

	if($_GET['action']=="ok")
	{
		$state=2;
		$srat1=mysql_query("update goodsorders set kuaidi='".$_POST['kuaidi']."',danhao='".$_POST['danhao']."',state='".$state."' where ordersid='".$_REQUEST['id']."'");
	    // 调用信息推送接口
	    $url = "http://120.24.0.10/xzpf/api/jpush/jpush.php?state=".$state."&ordersid=".$_POST[id];
	    file_get_contents($url);
	    // 调用信息推送接口 end
	}


	if($_GET[wancheng]=="ok")
	{
		$state=3;
		$srat=mysql_query("update goodsorders set state='".$state."' where ordersid='".$_GET[id]."'");

	    // 调用信息推送接口
	    $url = "http://120.24.0.10/xzpf/api/jpush/jpush.php?state=".$state."&ordersid=".$_GET[id];
	    file_get_contents($url);
	    // 调用信息推送接口 end
	}
	if(isset($_POST[kuaidi])){
		$state=2;
		$srat=mysql_query("update goodsorders set kuaidi='".$_POST[kuaidi]."',danhao='".$_POST[danhao]."',state='".$state."' where ordersid='".$_POST[ordersid]."'");

	    // 调用信息推送接口
	    $url = "http://120.24.0.10/xzpf/api/jpush/jpush.php?state=".$state."&ordersid=".$_POST[ordersid];
	    file_get_contents($url);
	    // 调用信息推送接口 end	
	    
		echo "<script>window.location.href='index.php?state=".$state."'</script>";
	}
	// 查找快递公司
	  $query=mysql_query("select * from express_delivery");
	  while ($row=mysql_fetch_assoc($query)) {
	    $express[]=$row;
	  }
	// 查找快递公司 end

	// 关闭订单 
	if ($_REQUEST['act'] == 'close') {
	  $query = mysql_query("select * from tuihuo where ordersid=".$_REQUEST['ordersid']);
	  $tuihuo = mysql_fetch_assoc($query);
	  if ($tuihuo) {
	    $query = mysql_query("DELETE FROM tuihuo where ordersid=".$_REQUEST['ordersid']);
	  }
	  $query = mysql_query("UPDATE goodsorders set state=6 where ordersid=".$_REQUEST['ordersid']);
	  if (mysql_affected_rows()>0) {
	    echo "<script>alert('订单关闭成功');window.location.href='index.php?state=6'</script>";
	  }else{
	    echo "<script>alert('订单关闭失败');window.location.href='index.php?state=6'</script>";
	  }
	}
	// 关闭订单 end

	// 取消退货 
	if ($_REQUEST['act'] == 'cancel') {
	  $query = mysql_query("select orderstate from tuihuo where ordersid=".$_REQUEST['ordersid']);
	  $tuihuo = mysql_fetch_assoc($query);
	  $orderstate = $tuihuo['orderstate'];

	  $query = mysql_query("DELETE FROM tuihuo where ordersid=".$_REQUEST['ordersid']);
	  $query = mysql_query("UPDATE goodsorders set state='".$orderstate."' where ordersid=".$_REQUEST['ordersid']);
	  if (mysql_affected_rows()>0) {
	    echo "<script>alert('取消退货成功');window.location.href='index.php?state=".$orderstate."'</script>";
	  }else{
	    echo "<script>alert('取消退货失败');window.location.href='index.php?state=".$orderstate."'</script>";
	  }
	}
	// 取消退货 end
	?>
	<script type="text/javascript" src="js/jquery.min.js"></script>
	<link href="css/styles.css" rel="stylesheet" type="text/css" />
	<link href="css/style2.css" rel="stylesheet" type="text/css" />
</head>
<body>
	<!--header-->
	<?php include("common/header.php");?>
	<!--header end-->
	<div id="sub_nav">
		<div id="subnav_wrap" class="container_12">
			<div id="subnav" class=" grid_12">
        <ul>

          <li><a href="index.php" <?php if($_GET['state']==""){echo 'class="sub_nav_active"';}?>>所有订单</a></li>
          <li><a href="index.php?state=0" <?php if($_GET['state']=="0"){echo 'class="sub_nav_active"';}?>>待付款</a></li>
          <!-- <li><a href="index.php?state=1" <?php if($_GET['state']=="1"){echo 'class="sub_nav_active"';}?>>待商家接单</a></li> -->
          <li><a href="index.php?state=8" <?php if($_GET['state']=="8"){echo 'class="sub_nav_active"';}?>>待发货</a></li>
          <!-- <li><a href="index.php?state=9" <?php if($_GET['state']=="9"){echo 'class="sub_nav_active"';}?>>商家拒绝接单</a></li> -->
          <li><a href="index.php?state=2" <?php if($_GET['state']=="2"){echo 'class="sub_nav_active"';}?>>待收货</a></li>
          <li><a href="index.php?state=3" <?php if($_GET['state']=="3"){echo 'class="sub_nav_active"';}?>>待评价</a></li> 
          <li><a href="index.php?state=4" <?php if($_GET['state']=="4"){echo 'class="sub_nav_active"';}?>>售后</a></li> 
          <!-- <li><a href="index.php?state=5" <?php if($_GET['state']=="5"){echo 'class="sub_nav_active"';}?>>交易完成</a></li>   -->
          <!-- <li><a href="index.php?state=6" <?php if($_GET['state']=="6"){echo 'class="sub_nav_active"';}?>>交易关闭</a></li>     -->
        </ul>

			</div>
		</div>
	</div>
	<div class="container_12">
		<?php 

		$rert=mysql_query("select * from goodsorders where ordersid ='".$_GET[id]."'"); 

		$sdg3=mysql_fetch_array($rert);


		$count2=mysql_query("select count(*) from car where  ordersid ='".$sdg3[ordersid]."'");

//获得订单记录总数
		$rs2=mysql_fetch_array($count2);
		$totalNumber2=$rs2[0];
		?>
		<div class="cy_mode" style="background: #fff; border:0px;">
			<strong>订单号：<?php echo $sdg3[numbers];?></strong>

    <?php if($sdg3['state']=="1" || $sdg3['state']=="7"){?>
    <div class="dr_in2" >等待商家接单</div>
    <?php }else if($sdg3['state']=="0"){?>
    <div class="dr_in2">等待客户付款</div>
    <?php }else if($sdg3['state']=="3"){?>
    <div class="dr_in2">等待客户评价</div>

    <?php 
    }else if($sdg3['state']=="4"){?>
    <?php
      $query = mysql_query("select * from tuihuo where ordersid=".$sdg3[ordersid]);
      $tuihuo = mysql_fetch_assoc($query);
      // 海淘
      if ($sdg3['type'] == 0) {
        if ($tuihuo[state]==1) { ?>
        <div class="dr_in2">待商家审核</div>

        <?php }elseif ($tuihuo[state]==2) { ?>

        	<?php if ($tuihuo[orderstate]==2 || $tuihuo[orderstate]==3) { ?>
            <div class="dr_in2">待用户确认退货</div>
          <?php }else{ ?>
        		<div class="dr_in close">关闭订单</div>
        	<?php } ?>

        <?php }elseif ($tuihuo[state]==3) { ?>
        <div class="dr_in2">商家拒绝退货</div>

        <?php }elseif ($tuihuo[state]==4) { ?>
        <div class="dr_in2">待商家确认回收</div>
        <?php }elseif ($tuihuo[state]==5) { ?>
        <div class="dr_in close">关闭订单</div>
        <?php }elseif ($tuihuo[state]==6) { ?>
        <div class="dr_in2">退货完成</div>
        <?php } 
      // 快购
      }elseif ($sdg3['type'] == 1) {
		if ($tuihuo[state]==1) { ?>
		<div class="dr_in cancel">取消退货</div>
        <div class="dr_in close">关闭订单</div>
        <?php } 
      }
	?>
    <?php }else if($sdg3['state']=="5"){?>
    <div class="dr_in2">交易完成</div>
    <?php }else if($sdg3['state']=="8"){?>
    <div class="dr_in2">待商家发货</div>
    <?php }else if($sdg3['state']=="9"){?>
    <div class="dr_in close">关闭订单</div>
    <?php }else if($sdg3['state']=="6"){?>
    <div class="dr_in2">交易关闭</div>
    <?php }else{?>
    <div class="dr_in2">待客户收货</div>
    <?php }?>
		</div>
		<?php 
		$state=1;
		$rert2=mysql_query("select * from car where  ordersid ='".$sdg3[ordersid]."' order by carid desc"); 
		while($sdg2=mysql_fetch_array($rert2))

		{	

			$rert=mysql_query("select * from goods where  goodsid ='".$sdg2[goodsid]."'"); 
			$sdg=mysql_fetch_array($rert);

			?>
			<div class="cy_mode" style="background:#FFFFFF; margin-top:0px;">
				<div class="dr_mimg"  onclick="javascript:window.location.href='/addgoods.php?gid=<?php echo $sdg2[goodsid]; ?>'" >
					<?php
					$ime=$sdg[images];
					$de = array();
					$de=explode("," ,$ime);
					$images=$de[0];
					?>
					<img src="<?php if($sdg[images]!=""){echo $images;}else{ echo "images/bg.jpg";} ?>" width="50%" height="auto">
				</div>
				<div class="dr_conm">

					<strong  onclick="javascript:window.location.href='/addgoods.php?gid=<?php echo $sdg2[goodsid]; ?>'"><?php echo $sdg[title]; ?></strong><span class="conf_wd all_fr">￥<?php echo $sdg2[price]; ?></span>
					<br/>
					<span class="conf_wd">规格：<?php echo $sdg2[fTitle].$sdg2[sTitle]; ?></span><span class="conf_wd all_fr">x<?php echo $sdg2[number]; ?></span>
					<br/>
					<span class="conf_wd all_fr">总计：￥<?php echo ($sdg2[price]*$sdg2[number]); ?></span>
					总计：<?php echo $totalNumber2; ?>件产品</span>
				</div>

			</div>
			<?php }?>
			<div class="cy_mode" style="background: #F79DDE; border:0px;">
				收货地址：<?php echo $sdg3[address]; ?><span style=" float:right;">
				下单时间：<?php echo  $sdg3[addtime];?></span>
			</div>
		</div>
	</div>
<!-- 遮罩层 -->
<div class="mask_div">
</div>
<!-- 遮罩层 end -->
<div class="alert_div">
  <div class="alert_title">
    填写快递单号
  </div> 
  <div class="alert_line"></div>
  <div class="alert_body">
    <form id="alert_form" action="" method="post">
      <label>快递公司:</label>
      <select name="kuaidi" class="select">
        <?php foreach ($express as $v) { ?>
        <option value="<?php echo $v[id]; ?>"><?php echo $v[name] ?></option>
        <?php } ?>
      </select>
      <label>快递单号:</label><input type="text" class="text" name="danhao" value="">
      <input type="hidden" name="ordersid" id="ordersid" value="">
    </form>
  </div>
  <div class="alert_foot">
    <button type="button" class="submit" id="submit">提交</button>
    <button type="button" class="submit" id="cancel">取消</button>
  </div>
<input type="hidden" id="id" value="<?php echo $_REQUEST[id]; ?>">
</div>
</body>
<script type="text/javascript">
  $('.send').click(function(){
    var ordersid=$('#id').val();
    $('#ordersid').attr('value',ordersid);
    $('.mask_div').show();
    $('.alert_div input[type="text"]').attr('value','');
    $('.alert_div').show();
  })
  $('#submit').click(function(){
    $('#alert_form').submit();
    $('.mask_div').hide();
    $('.alert_div').hide();
  });
  $('#cancel').click(function(){
    $('.mask_div').hide();
    $('.alert_div').hide();
  })

  // 关闭订单 
  $('.close').click(function(){
    var ordersid=$('#id').val();
    window.location.href='file2.php?act=close&ordersid='+ordersid;
  })
  // 关闭订单 end

  // 取消退货 
  $('.cancel').click(function(){
    var ordersid=$('#id').val();
    window.location.href='file2.php?act=cancel&ordersid='+ordersid;
  })
  // 取消退货 end
</script>
</html>
